﻿using System;
using System.Collections.Generic;

using E.BLL;
using E.Model;
using E.Enum;
using E.Web.UI.Page;

using X.Common;
using X.Pager;
using X.Pager.List;

namespace E.Web.Teacher.sys.notice
{
    public partial class List : TeacherBasePage
    {
        public IList<DictAreaModel> areaList;
        public IDictionary<int, string> categoryList;
        public string act;
        public int areaid;
        public int categoryid;
        public int sysSelection;
        public string title;
        public string fromdate;
        public string todate;
        public IList<ShortNoticeModel> noticeList;

        protected override void ShowPage()
        {
            areaList = GetTeacherAreaList(teacherid);

            NoticeBLL bll = new NoticeBLL();
            categoryList = bll.GetNoticeCategoryList();

            act = XRequest.GetString("act");
            title = XRequest.GetString("TitleTxt");
            fromdate = XRequest.GetString("FromDateTxt");
            todate = XRequest.GetString("ToDateTxt");
            categoryid = XRequest.GetInt("CategorySlt", -1);
            sysSelection = XRequest.GetInt("SysSlt", -1);

            if (areaList.Count == 1)
            {
                areaid = areaList[0].ID;
            }
            else
            {
                areaid = XRequest.GetInt("AreaSlt", -1);
            }

            if (ispost || act == "s")
            {
                SearchNoticeModel searchModel = new SearchNoticeModel();
                searchModel.Title = title;
                searchModel.CategoryID = categoryid;
                searchModel.SysSelection = sysSelection;
                searchModel.FromDate = fromdate;
                searchModel.ToDate = todate;
                searchModel.AreaID = areaid;
                searchModel.PublisherID = authority == EnumTeacherAuthority.Admin ? -1 : teacherid;
                searchModel.CertificateID = authority == EnumTeacherAuthority.Internals ? (new TeacherBLL()).GetTeacherProjectID(teacherid) : -1;

                NoticeListModel listModel = new NoticeListModel();

                CheckPageIndexValue(XRequest.GetInt("s", 1) - 1, XRequest.GetInt("g", 0), XRequest.GetInt("z", customerPageSize));

                listModel = bll.GetNoticeListByCondition(searchModel, customerPageSize, pageIndex);
                if (listModel.TotalCount > 0)
                {
                    count = listModel.TotalCount;
                    noticeList = listModel.List;
                    PagerBase pager = new ListPager(count, pageIndex, currentPgGroup, customerPageSize, defaultPagesInGroup);

                    Dictionary<string, string> parms = new Dictionary<string, string>();
                    parms.Add("act", act);
                    parms.Add("AreaSlt", areaid.ToString());
                    parms.Add("FromDateTxt", fromdate);
                    parms.Add("ToDateTxt", todate);
                    parms.Add("TitleTxt", title);
                    parms.Add("CategorySlt", categoryid.ToString());
                    parms.Add("SysSlt", sysSelection.ToString());
                    mypager = pager.DrawPager("selfpager", parms);
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
        }
    }
}
